import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:xiongan_app_yy/entrys/rp/inv_list_entity.dart';

class ListWidget extends StatefulWidget {
  final BuildContext context;
  final int index;
  final InvListData data;
  final String type;
  final ValueChanged<String> back;

  ListWidget(
      {this.context,
      this.index,
      @required this.data,
      this.type,
      this.back}); //@required data过几天记得加上

  @override
  State<StatefulWidget> createState() {
    return ListWidgetState(index);
  }
}

class ListWidgetState extends State<ListWidget> {
  int i;

  ListWidgetState(this.i);

  Widget stateWidget;
  String stateString;
  String strTips0;
  String strTips1;
  String str0;
  String str1;

  @override
  Widget build(BuildContext context) {
    if (widget.data.state == "未分配") {
      stateString = "未审核";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFF00A5F1)),
      );
    } else if (widget.data.state == "未审批") {
      stateString = "未审核";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFF00A5F1)),
      );
    } else if (widget.data.state == "未入库" || widget.data.state == "未出库") {
      stateString = "审核通过";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFF2FC480)),
      );
    } else if (widget.data.state == "已入库" || widget.data.state == "已出库") {
      stateString = "审核通过";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFF2FC480)),
      );
    }else if (widget.data.state == "待执行") {
      stateString = "审核通过";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFF2FC480)),
      );
    } else if (widget.data.state == "已驳回") {
      stateString = "审核未通过";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFFFB4747)),
      );
    }else if (widget.data.state == "已废弃"||widget.data.state == "已作废") {
      stateString = "已废弃";
      stateWidget = Text(
        stateString,
        style: TextStyle(fontSize: 14.0, color: Color(0xFFFB4747)),
      );
    }
    if (widget.type == "配送预约单") {
      strTips0 = "项目名称:";
      strTips1 = "配送地点:";
      str0 = widget.data.projectname;
      str1 = widget.data.destination;
    } else {
      strTips0 = "司机:";
      strTips1 = "类型:";
      str0 = widget.data.driver;
      str1 = widget.type;
    }
    return GestureDetector(
      child: Container(
        color: Colors.white,
        width: double.infinity,
        padding: EdgeInsets.all(10),
        margin: EdgeInsets.only(top: 10),
        child: Column(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(bottom: 10),
              child: Row(
                children: <Widget>[
                  /*Container(
                    child: Image.asset("assets/images/build.png",
                        fit: BoxFit.fill),
                    width: 60,
                    height: 60,
                    margin: EdgeInsets.only(right: 10),
                  ),*/
                  Expanded(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      RichText(
                        text: TextSpan(
                          text: strTips0,
                          style: TextStyle(
                              fontSize: 14.0, color: Color(0xff333333)),
                          children: <TextSpan>[
                            TextSpan(
                              text: str0,
                              style: TextStyle(
                                  fontSize: 14.0, color: Color(0xff333333)),
                            ),
                          ],
                        ),
                      ),
                      RichText(
                        text: TextSpan(
                          text: strTips1,
                          style: TextStyle(
                              fontSize: 14.0, color: Color(0xff333333)),
                          children: <TextSpan>[
                            TextSpan(
                              text: str1,
                              style: TextStyle(
                                  fontSize: 14.0, color: Color(0xff333333)),
                            ),
                          ],
                        ),
                      ),
                    ],
                  )),
                  Container(
                    child: Image.asset("assets/images/arrow.png",
                        fit: BoxFit.fill),
                    width: 8,
                    height: 13,
                  ),
                ],
              ),
            ),
            Divider(height: 1, color: Color(0xffdddddd)),
            Container(
                padding: EdgeInsets.only(top: 7),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: stateWidget,
                    ),
                    Text(
                      widget.data.creationTime ?? "",
                      style:
                          TextStyle(fontSize: 14.0, color: Color(0xff999999)),
                    )
                  ],
                ))
          ],
        ),
      ),
      onTap: () {
        print(widget.data.id);
        if (widget.type == "配送预约单") {
          Navigator.pushNamed(context, "/deliveryListDetails", arguments: {
            "id": widget.data.id,
            "type": widget.type,
            "state": stateString
          }).then((value) {
            widget.back(value);
          });
        } else if (widget.type == "工程结余退库预约单") {
          Navigator.pushNamed(context, "/return_booking_detail", arguments: {
            "id": widget.data.id,
            "type": widget.type,
            "state": stateString
          }).then((value) {
            widget.back(value);
          });
        } else if (widget.type == "入库预约单" || widget.type == "出库预约单") {
          Navigator.pushNamed(context, "/invListItemDetails", arguments: {
            "id": widget.data.id,
            "type": widget.type,
            "state": stateString
          }).then((value) {
            widget.back(value);
          });
        } else if (widget.type == "调配预约单") {
          Navigator.pushNamed(context, '/deploymentListDetailsNew', arguments: {
            "id": widget.data.id,
            "type": widget.type,
            "state": stateString
          }).then((value) {
            widget.back(value);
          });
        }
      },
    );
  }
}
